var util = require('../../utils/util');
var inputContent = {};
var app = getApp();
var that;
Page({
  data: {
  	prevPage:null,
  	nowdate: ""
    ,input:""
  },
  onLoad: function (options) {
    that = this;
    wx.setNavigationBarTitle( { title: "竞赛小组管理" });
	
	var pages = getCurrentPages();
    that.data.prevPage = pages[pages.length - 2];

    // console.log(that.data.prevPage.data.curindex);
    // console.log(that.data.prevPage.data.todos[that.data.prevPage.data.curindex].name);

    if(that.data.prevPage.data.curindex == -1){

    }else{
    	var name = that.data.prevPage.data.todos[that.data.prevPage.data.curindex].name;
    	that.setData({
    		nowdate:name
    	});
    }

  },
  sb:function(){
      setTimeout(that.sb2,500);
  },
  sb2: function () {

      var name = that.data.input;//inputContent["name"];
      name = name.replace(/(^\s*)|(\s*$)/g, "");
      if ( name == "") {
          util.alert("小组名不能为空");
          return false;
      }
      console.log(name);
      var todos = that.data.prevPage.data.todos;
      console.log(todos);
  	var curindex = that.data.prevPage.data.curindex;
  	console.log(curindex);
    if(curindex > -1){
        todos[curindex].name = name;
    }else{
      todos.push({
          name: name,
        id: 0
      })
    }
     
    that.data.prevPage.setData({
      todos: todos 
    })

     wx.navigateBack({
  		delta: 1
  	 })

  }
  ,bindChange: function(e) {
      ///inputContent[e.currentTarget.id] = e.detail.value
    that.setData({
      input : e.detail.value 
    });
    
  }
});